package lzl;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.util.Arrays;
import java.util.Properties;

@Intercepts({
        @Signature(type = Executor.class,method = "query",args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
)})
public class LzlPlugin implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("\nLzlPlugin.intercept().....start");
        System.out.println("method:\t"+invocation.getMethod());
        System.out.println("args:\t"+ Arrays.toString(invocation.getArgs()));//发现和@Signature配置的args参数一致
        System.out.println("class:\t"+invocation.getClass());
        System.out.println("LzlPlugin.intercept().....end\n");
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        System.out.println("LzlPlugin.plugin()......target="+target);
//        return target;
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println("LzlPlugin.setProperties()......  properties="+properties);
    }
}
